package com.lancoo.znbkxx.teacher.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.ClassVocabularyMasterDistribInfor
import com.lancoo.znbkxx.teacher.ui.adapter.AibkVocabularyMasterStuIntervalAdapter
import kotlinx.android.synthetic.main.aibk_dialog_student_interval_list.*

/*
* 班级词汇掌握分布图
* */
class DialogVocabularyMasterDistribList (
        context: Context?,
        val flag:Int,
        val typeStr:String,
        val classVocabularyMasterDistribInfor: ClassVocabularyMasterDistribInfor
) : Dialog(context!!, R.style.CustomDialog) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.aibk_dialog_student_interval_list)
        window!!.setGravity(Gravity.BOTTOM) //设置弹窗右对齐
        window!!.setWindowAnimations(R.style.MyDialogBottomTranslate) //设置动画效果

        val wl = window!!.attributes
        //以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        onWindowAttributesChanged(wl)
        setCanceledOnTouchOutside(true)

        //初始化界面数据
        initView()
    }

    /**
     * 初始化界面控件的显示数据
     */
    private fun initView() {

        //关闭dialog
        IvCloseDialog.setOnClickListener {
            dismiss()
        }

        var masterProject = ""
        if(typeStr == "L"){
            masterProject = "班级听说词汇量"
        }else if(typeStr == "R"){
            masterProject = "班级阅读词汇量"
        }
        var masterRank = ""
        if(flag == 0){
            masterRank = "掌握较差"
        }else if(flag == 1){
            masterRank = "掌握一般"
        }else if(flag == 2){
            masterRank = "掌握较好"
        }

        val distreIndex = classVocabularyMasterDistribInfor.DistreVocab
        TvTitleStuIntervalList.text = masterProject+"("+masterRank+distreIndex+")"

        val manager = LinearLayoutManager(context)
        manager.orientation = LinearLayoutManager.VERTICAL
        RvStuIntervalList.layoutManager = manager
        val mAdapter = AibkVocabularyMasterStuIntervalAdapter(context,classVocabularyMasterDistribInfor)
        mAdapter.setClickListener(object :AibkVocabularyMasterStuIntervalAdapter.OnClickListener{
            override fun onClick(pos: Int) {
//                MyToast.showToast("点击了$pos"+"project==="+typeStr)
                clickListener!!.onClick(pos)
            }
        })
        RvStuIntervalList.adapter = mAdapter

    }

    interface OnClickListener {
        fun onClick(pos:Int)
    }

    private var clickListener: OnClickListener? = null

    fun setClickListener(clickListener: OnClickListener?) {
        this.clickListener = clickListener
    }

}